/**
 *修改设备
 */
'use strict';

const conn = require('../../libs/DB/Conn');
const operationRecord = require("../sys/operationRecordAction");

module.exports = async function (params) {
    let result = await conn(`SELECT count(*) AS count FROM device_file WHERE device_no = "${params.deviceNo}" AND delete_sign = 1 AND device_id != ${params.deviceId}`);
    if(result[0].count > 0 ) return {success:false,message:"当前设备编号已存在。"}
    let updateObj ={
        device_no:params.deviceNo,
        device_name:params.deviceName,
    }
    let updateSql = `UPDATE device_file SET ? WHERE device_id = ?`;
    await conn(updateSql, [updateObj,params.deviceId]);
    await operationRecord(params);
    return { success: true };
};
